package com.ziyun.erp.web.modules.service.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.service.dto.ServiceRefundsConfirmDto;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.service.entity.ServiceRefundsEntity;
import com.ziyun.erp.modules.service.service.ServiceRefundsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 售后退款表
 *
 * @author zh
 * @email 296588519@qq.com
 * @date 2018-09-19 16:51:41
 */
@RestController
@RequestMapping("service/servicerefunds")
public class ServiceRefundsController {
    @Autowired
    private ServiceRefundsService serviceRefundsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("service:servicerefunds:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = serviceRefundsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{srId}")
    @RequiresPermissions("service:servicerefunds:info")
    public R info(@PathVariable("srId") Integer srId){
        ServiceRefundsEntity serviceRefunds = serviceRefundsService.selectById(srId);

        return R.ok().put("serviceRefunds", serviceRefunds);
    }

    /**
     * 获取确认退款相关信息
     */
    @RequestMapping("/getConfirmRefundInfo/{srSrId}")
    @RequiresPermissions("service:servicerefunds:info")
    public R getConfirmRefundInfo(@PathVariable("srSrId") Integer srSrId){
        ServiceRefundsConfirmDto serviceRefundsConfirm = serviceRefundsService.getConfirmRefundInfo(srSrId);

        return R.ok().put("serviceRefundsConfirm", serviceRefundsConfirm);
    }




    /**
     * 确认退款
     */
    @RequestMapping("/confirmRefund")
    @RequiresPermissions("service:servicerefunds:update")
    public R confirmRefund(@RequestBody ServiceRefundsEntity serviceRefunds){
        serviceRefunds.setSrUpdateName(UserUtils.getCurentUser().getUserId().toString());
        serviceRefundsService.confirmRefund(serviceRefunds);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("service:servicerefunds:delete")
    public R delete(@RequestBody Integer[] srIds){
        serviceRefundsService.deleteBatchIds(Arrays.asList(srIds));

        return R.ok();
    }

}
